package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.partner.PartnerSettleRecordMapper;
import com.net.xpay.common.domain.partner.PartnerSettleRecord;
import com.net.xpay.common.manager.partner.PartnerSettleRecordManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.model.search.PartnerSettleRecordSearchModel;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ReadTransactional
public class PartnerSettleRecordManagerImpl extends AbstractManager<PartnerSettleRecord> implements PartnerSettleRecordManager{

    @Autowired
    private PartnerSettleRecordMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerSettleRecord> getMapper() {
        return mapper;
    }

    @Override
    public List<PartnerSettleRecord> search(PartnerSettleRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(PartnerSettleRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    /**
     * 查询出某合伙人所有的未结算的统计记录
     *
     * @param partnerId 合伙人id
     * @return 统计记录
     */
    @Override
    public List<PartnerSettleRecord> listNoSettled(Long partnerId) {
        Preconditions.checkArgument(partnerId != null);
        PartnerSettleRecord condition = new PartnerSettleRecord();
        condition.setPartnerId(partnerId);
        condition.setSettled(false);
        return listByCondition(condition, Lists.newArrayList());
    }

    @Override
    public List<PartnerSettleRecord> listByIds(List<Long> ids) {
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(ids));
        return nonEmptyList(mapper.listByIds(ids));
    }
}
